﻿# // ***************************************************************************
# // 
# // Copyright (c) Scriptimus Ex Machina.  All rights reserved.
# // 
# // Microsoft Deployment Toolkit Support Script
# //
# // File:      ZTIConfigure-DHCP-Service.ps1
# // 
# // Version:   1.00 
# // 
# // Purpose:   Configure DHCP Server Role for Server 2008R2
# // 
# // ***************************************************************************

<#
.Synopsis
   Configure DHCP Server Role for Server 2008R2
.DESCRIPTION
   Create the Local Groups DHCP Users and DHCP Administrators. Set the DHCPServer service startuptype to automatic. Start the DHCP Server Service.
.EXAMPLE
   Example of how to use this cmdlet
.EXAMPLE
   This script is not configurable and will perform the tasks as hard coded.
   .\\ZTIConfigure-DHCP-Service.ps1
.NOTES
   Author: Andrew Barnes
   Version: 1.1
   Last updated: 14 November 2012
   Website: http:\\scriptimus.wordpress.com
.ROLE
   DHCP
.FUNCTIONALITY
   Configure DHCP Server
#>
    
Begin {

    Write-Host "Begining script"

    Function New-Group {

        <#
        .SYNOPSIS 
        Create a New Local Group

        .DESCRIPTION
        The New-Group.ps1 script will create a new group on a local machine.
    
        .PARAMETER Name
        Specifies the new name for the group.

        .PARAMETER Group
        Specifies the description to be added to the new group.

        .EXAMPLE
        .\New-Group -Name "DHCP users" -Description "DHCP user group"
        This will create a new user called "DHCP users" with the description "DHCP user group"

        .EXAMPLE
        .\New-Group "DHCP users" "DHCP user group"
        This will create a new user called "DHCP users" with the description "DHCP user group"

        .NOTES
        Author: Andrew Barnes
        Date: 15 September 2012

        .LINK
        Online version: http://scriptimus.wordpress.com
            
        #>

        Param(

        [String]$Name,

        [String]$Description

        )

        Begin{}

        Process{

            Write-Host "Creating Local Group: $Name"

            $Computer = [adsi]"WinNT://$env:COMPUTERNAME"

            $Group = $Computer.Create("Group", $Name)

            $Group.SetInfo()

            If ($Description) {

                $Group.Description = $Description

                $Group.SetInfo()

                    }
                }
        End{}

        }

    }

Process {

    Write-Host "Processing Script"

    # \\ Create LocalGroup DHCP Users

    New-Group -Name "DHCP Users" -Description "Members have read-only DHCP console access to the server"

    #  \\ Create LocalGroup DHCP Administrators 

    New-Group -Name "DHCP Administrators" -Description "Members can view and modify any data on the DHCP server."

    # \\ Configure DHCP startup mode

    Write-Host "Setting DHCP startup mode to Automatic"

    Set-Service -Name dhcpserver -StartupType Automatic

    # \\ Start DHCP Service

    Write-Host "Starting DHCP Service."

    Start-Service dhcpserver -Warningaction SilentlyContinue

    }

End {
    Write-Host "End Script"
    }
